clear
*cd $data 
cd "C:\Users\JGW99\Dropbox\Forest\Data"

use OwnerPopulation /*created by a line in 2_jw_compiling_cleaning*/

log using CEE_Data\owner_population_analysis_R1, replace

*********************************************
*Identifying non-family owners
************************************************

*Identify salient public organizations

gen ipublic=0

gen f3=substr(owner_name,1,3)
replace ipublic=1 if f3=="pa "

gen f6=substr(owner_name,1,6)
replace ipublic=1 if f6=="county"
replace ipublic=1 if f6=="penna "

gen f7=substr(owner_name,1,7)
replace ipublic=1 if f7=="comm of"

gen f9=substr(owner_name,1,9)
replace ipublic=1 if f9=="municipal" | f9=="township "

gen f12=substr(owner_name,1,12)
replace ipublic=1 if f12=="commonwealth"

gen f13=substr(owner_name,1,13)
replace ipublic=1 if f13=="pennsylvania "

gen l7=substr(owner_name,-7,.)
replace ipublic=1 if l7=="borough" | l7== " county"

gen l8=substr(owner_name,-8,.)
replace ipublic=1 if l8=="township"

gen l9=substr(owner_name,-9,.)
replace ipublic=1 if l9=="authority" | l9==" district"

replace ipublic=1 if owner_name=="western pennsylvania conservancy" | owner_name=="western pa conservancy"

*Identifying timber companies, corporations etc

gen idrop=(strpos(owner_name, " inc ") >0 | strpos(owner_name, " inc. ") >0 | strpos(owner_name, "timber") >0 | strpos(owner_name, "logging")>0 /*
*/ | strpos(owner_name, "coal") >0 | strpos(owner_name, "mining")>0 | strpos(owner_name, "coastal forest")>0 | strpos(owner_name, "fayette forest")>0 /*
*/ | strpos(owner_name, "appalachian timber")>0 | strpos(owner_name, "hale forestry")>0| strpos(owner_name, "forest products")>0 |strpos(owner_name, "pennstress")>0 ) 

gen nonfamily=(ipublic==1 |idrop==1)

qui: sum cama_acres
scalar countyacres=r(N)*r(mean)

qui: sum forestAcres
scalar totacres=r(N)*r(mean)

qui: sum forestAcres if nonfamily==0
scalar famacres=r(N)*r(mean)

di "Percent of sample area forested " totacres/countyacres
di "Percent of sample forested acrea family owned " famacres/totacres

*average family forested acreage ownership
drop if nonfamily==1

*collapsing to ownerlevel
collapse (sum) forestAcres, by(owner_name owner_lat owner_long)

*average acreage among 
gen forestHa=forestAcres/2.47
mean forestHa if forestAcres>=10 /*72 acres!*/

log close

translate CEE_Data\owner_population_analysis_R1.smcl CEE_Data\owner_population_analysis_R1.pdf

